package com.headwire.kw.helpers;

public class CodeHolder {
	private static int x = 1;
	public static void derp(String s) {
		//curl -F"sling:resourceType=foo/bar" -F"title=some title" http://admin:admin@localhost:8888/content/mynode
		StringBuilder out = new StringBuilder();
		out.append("curl -F\"text=");
		out.append(s);
		out.append("\" -F\"value=");
		out.append(s);
		out.append("\"");
		out.append(" http://admin:admin@localhost:4504/apps/konakart/components/konakart/dialog/items/kkjsp/options/");
		out.append(x);
		x++;
		System.out.println(out);
	}
	
	// designed to be used by FileLineTransformer
	public static String transformLine(String s) {
		//return transformRepoRoot(s);
		return transformNodeName(s);
	}
	
	public static String transformNodeName(String s) {
		String[] splt = s.split("\t");
		
		String[] flipbook = splt[0].split("\\|");
		
		// only need ontv and specials
		if(!flipbook[0].equals("ontv") && !flipbook[0].equals("specials")) {
			return "";
		}
		
		StringBuilder reporoot = new StringBuilder();
		reporoot.append("NODE_NAME_");
		reporoot.append(flipbook[0]);
		if(!flipbook[1].equals("-")) {
			reporoot.append("_").append(flipbook[1]);
		}
		if(!flipbook[2].equals("-")) {
			reporoot.append("_").append(flipbook[2]);
		}
		
		reporoot.append("=\"photos\"");
		
		return reporoot.toString();
	}
	
	public static String transformRepoRoot(String s) {
		String[] splt = s.split("\t");
		//System.out.println(splt.length+" "+splt[0]+" "+splt[1]);
		String[] flipbook = splt[0].split("\\|");
		//System.out.println(flipbook.length+"  "+flipbook[0]+"  "+flipbook[1]+"  "+flipbook[2]);
		// repo root uses filename
		// node root uses some other shit
		StringBuilder reporoot = new StringBuilder();
		reporoot.append("REPO_ROOT_fb_");
		reporoot.append(flipbook[0]);
		if(!flipbook[1].equals("-")) {
			reporoot.append("_").append(flipbook[1]);
		}
		if(!flipbook[2].equals("-")) {
			reporoot.append("_").append(flipbook[2]);
		}
		
		String path = splt[1].substring(7).replace("/<year>/<month>/", "");
		path = path.substring(0,path.lastIndexOf('/'));
		
		reporoot.append("=\"/content/betcom");
		reporoot.append(path).append("\"");
		
		return reporoot.toString();
	}
}
